package activity.LocalFile;

import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import com.hichip.campro.R;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import activity.video.VideoLocalFragment;
import activity.video.adapter.VpVideoAdapter;
import base.HiActivity;
import bean.LeftLocalFileBean;
import bean.MyCamera;
import butterknife.BindView;
import common.HiDataValue;
import utils.HiTools;

//本地文件 界面  真正程序使用的
public class LocalFileActivity2 extends HiActivity implements View.OnClickListener {

    @BindView(R.id.btn_return) ImageView btn_return;
    @BindView(R.id.tablayout) TabLayout tabLayout;
    @BindView(R.id.viewPager) ViewPager viewPager;
    private MyCamera mMyCamera;
    private String root_path;

    @Override
    protected int setLayoutId() {
        return R.layout.activity_local_file_2;
    }

    @Override
    protected void init(@Nullable Bundle savedInstanceState) {
        getIntentData();
        root_path=getFilesDir() + "/android/data/" + HiDataValue.APP_NAME + "/";
        initViewAndData();
        setOnListeners();
    }

    private void getIntentData() {
       String str_uid= getIntent().getStringExtra(HiDataValue.EXTRAS_KEY_UID);
       if(!TextUtils.isEmpty(str_uid)){
           for (MyCamera camera:HiDataValue.CameraList){
               if(str_uid.equals(camera.getUid())){
                   this.mMyCamera=camera;
                   break;
               }
           }
       }
    }

    private void setOnListeners() {
        btn_return.setOnClickListener(this);
    }

    private void initViewAndData() {
        tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.tit_video)));
        tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.tit_photo)));
        List<String> titles=new ArrayList<>();
        titles.add(getString(R.string.tit_video));
        titles.add(getString(R.string.tit_photo));
        List<Fragment> fragments=new ArrayList<>();
        fragments.add(new VideoLocalFragment());

        LocalPhotoFragment localPhotoFragment=new LocalPhotoFragment();
        Bundle bundle=new Bundle();
        LeftLocalFileBean bean=new LeftLocalFileBean();
        bean.setUid(mMyCamera.getUid());
        bean.setFile(new File(root_path+mMyCamera.getUid()));
        bundle.putSerializable("bean",bean);
        localPhotoFragment.setArguments(bundle);
        fragments.add(localPhotoFragment);

        VpVideoAdapter adapter=new VpVideoAdapter(getSupportFragmentManager(),fragments,titles);
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_return:
                finish();
                break;
        }
    }


    public MyCamera getmMyCamera(){
        return this.mMyCamera;
    }

}


